//% color="#4169E1" iconWidth=50 iconHeight=40
namespace DFRobot_HX711_I2C{

    //% block="Initialize the weight sensor until successful, address [ADDR]" blockType="command" 
    //% ADDR.shadow="dropdown" ADDR.options="ADDR"
    export function DFRobot_HX711_I2CInit(parameter: any, block: any) {
        let addr = parameter.ADDR.code;
        
        Generator.addInclude("DFRobot_HX711_I2CInit", "#include <DFRobot_HX711_I2C.h>");
        
        Generator.addObject("DFRobot_HX711_I2CInit","DFRobot_HX711_I2C",`MyScale(&Wire, ${addr});`);
  
        Generator.addCode(`while (!MyScale.begin());`);
       
        
    }
    //% block="Set the calibration value [NUMBER]" blockType="command"
    //% NUMBER.shadow="number" NUMBER.defl="100"
    export function DFRobot_HX711_I2CSetCalWeight(parameter: any, block: any) { 
        let number=parameter.NUMBER.code;

        Generator.addCode(`MyScale.setCalWeight(${number});`);
     
   
   }
    //% block="Set the sensor auto-calibration trigger threshold [NUMBER1]" blockType="command"
    //% NUMBER1.shadow="number" NUMBER1.defl="30"
    export function DFRobot_HX711_I2CSetThreshold(parameter: any, block: any) { 
      let number1=parameter.NUMBER1.code;

      Generator.addCode(`MyScale.setThreshold(${number1});`);
   
    }
    //% block="Enable calibration(software mode)" blockType="command"
    export function DFRobot_HX711_I2CEnableCal(parameter: any, block: any) { 
        
        Generator.addCode(`MyScale.enableCal();`);
   
   }
   
    //% block="Calibration is successful?" blockType="boolean" 
    export function DFRobot_HX711_I2CGetCalFlag(parameter: any, block: any) { 
      Generator.addCode( `MyScale.getCalFlag()`);

  }
   /*  //% block="DFRobot_HX711_I2C  peel  " blockType="command"
     
     export function DFRobot_HX711_I2CPeel(parameter: any, block: any) { 
        

        Generator.addSetup(`DFRobot_HX711_I2CInit5`,`MyScale.peel();`);
   
   }*/

  //% block="Set/update calibration value" blockType="command" 
  export function DFRobot_HX711_I2CSetCalibration(parameter: any, block: any) { 
      
    Generator.addCode(`MyScale.setCalibration(MyScale.getCalibration());`);

  }

   //% block="Obtain weight" blockType="reporter" 
   export function DFRobot_HX711_I2CReadWeight(parameter: any, block: any) { 
      
    Generator.addCode( [`MyScale.readWeight()`,Generator.ORDER_UNARY_POSTFIX]);

}

  //% block="---"
  export function noteSep() {

  }

    //% block="Obtain calibration value" blockType="reporter" 
    export function DFRobot_HX711_I2CGetCalibration(parameter: any, block: any) { 

        Generator.addCode(`MyScale.getCalibration()`);
   
   }

    //% block="Set/update calibration value [NUMBER2] (manual mode)" blockType="command" 
    //% NUMBER2.shadow="number" NUMBER2.defl="2000"
    export function DFRobot_HX711_I2CSetCalibration1(parameter: any, block: any) { 
      let number2=parameter.NUMBER2.code;
        
      Generator.addCode(`MyScale.setCalibration(${number2});`);
   
   }


}